﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace version1
{
    public class MapCell : Visible
    {
        public int _nrow;

        public int Nrow
        {
            get { return _nrow; }
            set { _nrow = value; }
        }
        public int _ncol;

        public int Ncol
        {
            get { return _ncol; }
            set { _ncol = value; }
        }
        public Map[,] _map;

        public Map[,] Map
        {
            get { return _map; }
            set { _map = value; }
        }

        
        public float _scale = 1.0f;

        public float Scale
        {
            get { return _scale; }
            set { _scale = value; }
        }
        public int cellwidth = 97;
        public int cellheight = 49;

        public MapCell(ContentManager content, List<string> str,int nCellType,int nrow, int ncol,int [,] cell, Vector2 top)
        {
            _TopLeft = top;  
            sprite = new List<Sprite2D>();
            nsprite = 0;
            Ncol = ncol;
            Nrow = nrow;
            float xx = 0;
            float yy = 0;
            Map=new Map[nrow,ncol];
            for (int i = 0; i < nrow; i++)
            {
                for (int j = 0; j < ncol; j++)
                {                  
                    Map[i, j] = new Map(content, str[cell[i, j]],new Vector2(xx,yy),new Vector2(cellwidth, cellheight));
                    xx += 97 / 2;
                    yy -= 49 / 2;
                }
                yy = 0;
                xx = 0;
                xx = 97 / 2 * i;
                yy = 49 / 2 * i;
            }
        }
        public override void Draw(SpriteBatch spritebatch, GameTime gameTime)
        {
            for (int i = 0; i < Nrow; i++)
                for (int j = 0; j < Ncol; j++)
                {
                    //Vector2 temp = new Vector2();
                    //temp.X = j * cellwidth - TopLeft.X;
                    //temp.Y = i * cellheight - TopLeft.Y;
                    //Map[i, j].TopLeft = temp;
                    Map[i, j].Draw( spritebatch,gameTime); 
                    
                }
                
        }
        public  void Update(GameTime gametime, int x, int y)
        {
            for (int i = 0; i < Nrow; i++)
                for (int j = 0; j < Ncol; j++)
                {
                    Map[i,j].Update(gametime, x,  y);
                }
            
        }
    }
}
